home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / exarray.com / XMANAGER.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1989-08-19  |  3.5 KB  |  148 lines

  1. Unit XManager;  
  2. {$R-,S-.O+}
  3.  
  4. { The Manager Object provides the ExtendedTable with information on all      }
  5. { Lobes of the ExtendedArray.  The priority, loaded status and diskfile name }
  6. { are all tracked by the Manager.  In the case where the searched for Lobe   }
  7. { is already loaded into one of the ExtendedTable's buffers, the array       }
  8. { address is stored as well.  By consulting the Manager, the Table can       }
  9. { always provide the needed Lobe to the ExtendedArray.                       }
  10.  
  11. INTERFACE
  12.  
  13. Uses GenArray,XGlobals;
  14.  
  15. Type
  16.   ManRec = Record
  17.              Tag     : Short;
  18.              Loaded  : Boolean;
  19.              Address : Byte;
  20.              Pri     : LongInt;
  21.                                   {Address in 0..MaxBuff implies Loaded
  22.                                   Address of MaxBuff+1 implies Not Loaded}
  23.            End;
  24.  
  25.   Manager = Object (FlexArray)
  26.  
  27.                    {
  28.                      Procedure Create;
  29.                      Procedure Destroy;
  30.                    }
  31.  
  32.                      Procedure Init (NumLobes : Word);
  33.                      Procedure SetTag (Index : Word; Tag : Short);
  34.                      Procedure Load (Index : Word; Address : Byte);
  35.                      Procedure UnLoad (Index : Word);
  36.  
  37.                      Function ManIndex (Tag : Short) : Word;
  38.                      Function MemIndex (Index : Word) : Byte;
  39.                      Function GetTag (Index : Word) : Short;
  40.                      Function PriIndex (Index : Word) : LongInt;
  41.                      Function InMem (Index : Word) : Boolean;
  42.  
  43.                    {
  44.                      Function MaxSize : Word;
  45.                    }
  46.             End;
  47.  
  48. IMPLEMENTATION
  49.  
  50. Procedure Manager.Init (NumLobes : Word);
  51. Var
  52.   M : ManRec;
  53.   I : Word;
  54. Begin
  55.   FlexArray.Init (NumLobes,SizeOf(ManRec));
  56.   For I := 0 to NumLobes-1 do
  57.     Begin
  58.       Retrieve (M,I,SizeOf(M));
  59.       M.Tag := '';
  60.       M.Loaded := False;
  61.       M.Address := MaxBuff+1;
  62.       M.Pri := 0;
  63.       Accept (M,I,SizeOf(M))
  64.     End
  65. End;
  66.  
  67. Procedure Manager.SetTag (Index : Word; Tag : Short);
  68. Var
  69.   M : ManRec;
  70. Begin
  71.   Retrieve (M,Index,SizeOf(M));
  72.   M.Tag := Tag;
  73.   Accept (M,Index,SizeOf(M))
  74. End;
  75.  
  76. Procedure Manager.Load (Index : Word; Address : Byte);
  77. Var
  78.   M : ManRec;
  79. Begin
  80.   Retrieve (M,Index,SizeOf(M));
  81.   M.Loaded := True;
  82.   M.Address := Address;
  83.   M.Pri := M.Pri + 1;        {Increment Priority for Indexth Lobe each time
  84.                               it must be loaded from disk.}
  85.   Accept (M,Index,SizeOf(M))
  86. End;
  87.  
  88. Procedure Manager.UnLoad (Index : Word);
  89. Var
  90.   M : ManRec;
  91. Begin
  92.   Retrieve (M,Index,SizeOf(M));
  93.   M.Loaded := False;
  94.   M.Address := MaxBuff+1;
  95.   Accept (M,Index,SizeOf(M))
  96. End;
  97.  
  98. Function Manager.GetTag (Index : Word) : Short;
  99. Var
  100.   M : ManRec;
  101. Begin
  102.   Retrieve (M,Index,SizeOf(M));
  103.   GetTag := M.Tag;
  104. End;
  105.  
  106. Function Manager.ManIndex (Tag : Short) : Word;
  107. Var
  108.   M : ManRec;
  109.   T : Short;
  110.   I : Word;
  111. Begin
  112.   I := 0;
  113.   T := GetTag (I);
  114.   While T <> Tag do
  115.     Begin
  116.       I := I + 1;
  117.       T := GetTag (I)
  118.     End;
  119.   ManIndex := I
  120. End;
  121.  
  122. Function Manager.MemIndex (Index : Word) : Byte;
  123. Var
  124.   M : ManRec;
  125. Begin
  126.   Retrieve (M,Index,SizeOf(M));
  127.   MemIndex := M.Address;
  128. End;
  129.  
  130. Function Manager.PriIndex (Index : Word) : LongInt;
  131. Var
  132.   M : ManRec;
  133. Begin
  134.   Retrieve (M,Index,SizeOf(M));
  135.   PriIndex := M.Pri;
  136. End;
  137.  
  138. Function Manager.InMem (Index : Word) : Boolean;
  139. Var
  140.   M : ManRec;
  141. Begin
  142.   Retrieve (M,Index,SizeOf(M));
  143.   InMem := M.Loaded
  144. End;
  145.  
  146. BEGIN
  147. END.
  148.